/*
 *    Copyright (c) 2018-2025, cloud All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cloud
 */

package com.fuyao.cloud.admin.bulletin;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fuyao.cloud.common.core.model.BaseEntity;
import com.fuyao.cloud.common.core.model.FyUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 通知公告
 *
 * @author lyhills
 * @date 2023-06-29 17:38:50
 */
@Data
@TableName("fy_bulletin")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "通知公告")
public class Bulletin extends BaseEntity<Bulletin> {

    private static final long serialVersionUID = 1L;
    /**
     * 唯一编码（用于关联附件）
     */
    @ApiModelProperty(value="唯一编码（用于关联附件）")
    private String unid;
    /**
     * 类型编码
     */
    @ApiModelProperty(value="类型编码")
    private String typeCode;

    /**
     * 类型名称
     */
    @ApiModelProperty(value="类型名称")
    private String typeName;

    /**
     * 状态： 0：草稿，1：已发布
     */
    @ApiModelProperty(value="状态： 0：草稿，1：已发布")
    private String status;

    /**
     * 主题
     */
    @ApiModelProperty(value="主题")
    private String subject;

    /**
     * 内容
     */
    @ApiModelProperty(value="内容")
    private String content;

    /**
     * 发布时间
     */
    @ApiModelProperty(value="发布时间")
    private LocalDateTime pushTime;

    /**
     * 是否发布至首页：N:否，Y:是
     */
    @ApiModelProperty(value="是否发布至首页：N:否，Y:是")
    private String pushFirstPage;

    /**
     * 发布类型：{ALL:全部，USER:指定用户: GROUP:指定岗位,UNIT:单位}
     */
    @ApiModelProperty(value="发布类型：{ALL:全部，USER:指定用户: GROUP:指定岗位,UNIT:单位}")
    private String pushType;

    /**
     * 是否发布OA: N:否，Y:是
     */
    @ApiModelProperty(value="是否发布OA: N:否，Y:是")
    private String mobileoa;

    /**
     * CRON表达式
     */
    @ApiModelProperty(value="CRON表达式")
    private String cronExpression;

    /**
     * 备注
     */
    @ApiModelProperty(value="备注")
    private String remarks;

    @ApiModelProperty(value="发布用户ID")
    private Long pushUserId;

    @ApiModelProperty(value="发布用户名称")
    private String pushUserName;

    @ApiModelProperty(value="发布用户部门ID")
    private Long pushUserDeptId;

    @ApiModelProperty(value="发布用户部门全名称")
    private String pushUserDeptFullname;

    @TableField(exist = false)
    @ApiModelProperty(value="浏览次数")
    private Long browseRecordCount;

    @TableField(exist = false)
    @ApiModelProperty(value="发布用户部门名称")
    private String pushUserOuName;

    // 获取部门名称
    public String getPushUserOuName() {
        if (StrUtil.isEmpty(this.pushUserDeptFullname)) {
            return "";
        } else {
            return this.pushUserDeptFullname.contains(".") ? this.pushUserDeptFullname.substring(this.pushUserDeptFullname.indexOf(".") + 1) : this.pushUserDeptFullname;
        }
    }

    @JsonIgnore
    public void setPushUser(FyUser user) {
        this.pushUserId = user.getId();
        this.pushUserName = user.getName();
        this.pushUserDeptId = user.getDeptId();
        this.pushUserDeptFullname = user.getFullName();
    }
}
